Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

🐛 check if the username begins or ends with a period #368

Closed
wants to merge 1 commit into from
Closed

🐛 check if the username begins or ends with a period #368

wants to merge 1 commit into from

Conversation

tschwaerzl
Copy link

Check if the given username startswith or endswith a period.

Fixes #228

@Komposten
Copy link
Member

I think this needs to be elaborated a bit more. Even after this change you can still have names like _, _..._, a.....a, etc.

@duichwer
Copy link

duichwer commented Oct 4, 2019

Maybe we want something like the following:

(?!\.)[a-zA-Z0-9]*([._]?[a-zA-Z0-9]+)*(?<!\.)

This enforces minimum one of a-zA-Z0-9 and allows one of the special chars [._] in a row.

I'm not sure but with enforcing one character behind the special chars, the negative lookbehind could also be removed.
At the moment underscores aren't possible too at the end.

Another Option:

(?!\.)[a-zA-Z0-9]*([._]?[a-zA-Z0-9]+[._]?)*(?<!\.)

@lifenautjoe
Copy link
Member

Hmm, should be alphanumeric and _ and ., where those 2 characters can't be by themselves or the beginning nor end of the username

@duichwer
Copy link

duichwer commented Oct 4, 2019

I don't understand what you mean by "where those 2 characters can't be by themselves".
Do you mean, that we don't to allow the examples of @Komposten, but we allow something link a.b.c_d_e?

@Komposten
Copy link
Member

Komposten commented Oct 4, 2019

Since we're checking a bounded string there is no reason to have lookaheads and lookbehinds. Better to define a concrete regex for the pattern we want, rather than trying to match what we don't want.

To that end we can simply the regex to something like this:

^[a-zA-Z0-9](?:[._]?[a-z-A-Z0-9])*$

Basically, always start with at least one alphanumeric character.
Follow that up with zero or more alphanumeric characters, each of which may be preceded by exactly one period or underscore.

I haven't done extensive testing, but here are some examples (highlight = match):
image

@duichwer
Copy link

duichwer commented Oct 5, 2019

@Komposten thanks for the small fixes to my proposed regex. :)
@lifenautjoe how will we handle usernames that exist that aren't allowed with the new check anymore? I also found a username with a é, which isn't allowed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants